{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "zkufh760uvF3"
   },
   "source": [
    "![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)\n",
    "\n",
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/nlu/blob/master/examples/colab/Training/binary_text_classification/NLU_training_sarcasam_classifier_demo_news_headlines.ipynb)\n",
    "\n",
    "\n",
    "# Training a Sentiment Analysis Classifier with NLU\n",
    "## 2 Class  News Headlines Sarcasam Training\n",
    "With the [SentimentDL model](https://nlp.johnsnowlabs.com/docs/en/annotators#sentimentdl-multi-class-sentiment-analysis-annotator)  from Spark NLP you can achieve State Of the Art results on any multi class text classification problem\n",
    "\n",
    "This notebook showcases the following features :\n",
    "\n",
    "- How to train the deep learning classifier\n",
    "- How to store a pipeline to disk\n",
    "- How to load the pipeline from disk (Enables NLU offline mode)\n",
    "\n",
    "You can achieve these results or even better on this dataset with training data:\n",
    "\n",
    "\n",
    "<br>\n",
    "\n",
    "![img.png]()\n",
    "\n",
    "You can achieve these results or even better on this dataset with test  data:\n",
    "\n",
    "\n",
    "<br>\n",
    "\n",
    "![Screenshot 2021-02-25 150812.png]()\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "dur2drhW5Rvi"
   },
   "source": [
    "# 1. Colab Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "hFGnBCHavltY"
   },
   "outputs": [],
   "source": [
    "! pip install -q johnsnowlabs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "f4KkTfnR5Ugg"
   },
   "source": [
    "# 2. Download News Headlines Sarcsam dataset\n",
    "https://www.kaggle.com/rmisra/news-headlines-dataset-for-sarcasm-detection\n",
    "#Context\n",
    "Past studies in Sarcasm Detection mostly make use of Twitter datasets collected using hashtag based supervision but such datasets are noisy in terms of labels and language. Furthermore, many tweets are replies to other tweets and detecting sarcasm in these requires the availability of contextual tweets.\n",
    "\n",
    "To overcome the limitations related to noise in Twitter datasets, this News Headlines dataset for Sarcasm Detection is collected from two news website. TheOnion aims at producing sarcastic versions of current events and we collected all the headlines from News in Brief and News in Photos categories (which are sarcastic). We collect real (and non-sarcastic) news headlines from HuffPost.\n",
    "\n",
    "This new dataset has following advantages over the existing Twitter datasets:\n",
    "\n",
    "Since news headlines are written by professionals in a formal manner, there are no spelling mistakes and informal usage. This reduces the sparsity and also increases the chance of finding pre-trained embeddings.\n",
    "\n",
    "Furthermore, since the sole purpose of TheOnion is to publish sarcastic news, we get high-quality labels with much less noise as compared to Twitter datasets.\n",
    "\n",
    "Unlike tweets which are replies to other tweets, the news headlines we obtained are self-contained. This would help us in teasing apart the real sarcastic elements.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "OrVb5ZMvvrQD"
   },
   "outputs": [],
   "source": [
    "! wget https://s3.amazonaws.com/auxdata.johnsnowlabs.com/public/resources/en/classifier-dl/Sarcasm_Headlines/Sarcasm_Headlines_Dataset_v2.csv\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 424
    },
    "id": "y4xSRWIhwT28",
    "outputId": "3b062b61-bd33-4f03-902e-066900be06d1"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"df-907766e7-9455-426a-9192-6b499f9bc45e\" class=\"colab-df-container\">\n",
       "    <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "      <th>text</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1875</th>\n",
       "      <td>negative</td>\n",
       "      <td>this t. rex dominates 'american ninja warrior'...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11997</th>\n",
       "      <td>negative</td>\n",
       "      <td>computer science in vietnam: counting down to ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>315</th>\n",
       "      <td>positive</td>\n",
       "      <td>dhs announces racial profiling free-for-all th...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16252</th>\n",
       "      <td>negative</td>\n",
       "      <td>the best rent the runway dresses for bridesmaids</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12178</th>\n",
       "      <td>negative</td>\n",
       "      <td>abe's visit will remind americans china's powe...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10908</th>\n",
       "      <td>positive</td>\n",
       "      <td>sudden death of aunt creates rupture in family...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17451</th>\n",
       "      <td>negative</td>\n",
       "      <td>over 50% of lgbtq youths struggle with eating ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16032</th>\n",
       "      <td>negative</td>\n",
       "      <td>gop senator: my family went from 'cotton to co...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17823</th>\n",
       "      <td>negative</td>\n",
       "      <td>martin o'malley fails to make ohio's president...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14495</th>\n",
       "      <td>positive</td>\n",
       "      <td>nra says parkland students should be grateful ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>22895 rows × 2 columns</p>\n",
       "</div>\n",
       "    <div class=\"colab-df-buttons\">\n",
       "\n",
       "  <div class=\"colab-df-container\">\n",
       "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-907766e7-9455-426a-9192-6b499f9bc45e')\"\n",
       "            title=\"Convert this dataframe to an interactive table.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
       "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
       "  </svg>\n",
       "    </button>\n",
       "\n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    .colab-df-buttons div {\n",
       "      margin-bottom: 4px;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "    <script>\n",
       "      const buttonEl =\n",
       "        document.querySelector('#df-907766e7-9455-426a-9192-6b499f9bc45e button.colab-df-convert');\n",
       "      buttonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "      async function convertToInteractive(key) {\n",
       "        const element = document.querySelector('#df-907766e7-9455-426a-9192-6b499f9bc45e');\n",
       "        const dataTable =\n",
       "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                    [key], {});\n",
       "        if (!dataTable) return;\n",
       "\n",
       "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "          + ' to learn more about interactive tables.';\n",
       "        element.innerHTML = '';\n",
       "        dataTable['output_type'] = 'display_data';\n",
       "        await google.colab.output.renderOutput(dataTable, element);\n",
       "        const docLink = document.createElement('div');\n",
       "        docLink.innerHTML = docLinkHtml;\n",
       "        element.appendChild(docLink);\n",
       "      }\n",
       "    </script>\n",
       "  </div>\n",
       "\n",
       "\n",
       "<div id=\"df-b394439c-c364-444d-9390-e0e00eec93bb\">\n",
       "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-b394439c-c364-444d-9390-e0e00eec93bb')\"\n",
       "            title=\"Suggest charts.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "     width=\"24px\">\n",
       "    <g>\n",
       "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
       "    </g>\n",
       "</svg>\n",
       "  </button>\n",
       "\n",
       "<style>\n",
       "  .colab-df-quickchart {\n",
       "      --bg-color: #E8F0FE;\n",
       "      --fill-color: #1967D2;\n",
       "      --hover-bg-color: #E2EBFA;\n",
       "      --hover-fill-color: #174EA6;\n",
       "      --disabled-fill-color: #AAA;\n",
       "      --disabled-bg-color: #DDD;\n",
       "  }\n",
       "\n",
       "  [theme=dark] .colab-df-quickchart {\n",
       "      --bg-color: #3B4455;\n",
       "      --fill-color: #D2E3FC;\n",
       "      --hover-bg-color: #434B5C;\n",
       "      --hover-fill-color: #FFFFFF;\n",
       "      --disabled-bg-color: #3B4455;\n",
       "      --disabled-fill-color: #666;\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart {\n",
       "    background-color: var(--bg-color);\n",
       "    border: none;\n",
       "    border-radius: 50%;\n",
       "    cursor: pointer;\n",
       "    display: none;\n",
       "    fill: var(--fill-color);\n",
       "    height: 32px;\n",
       "    padding: 0;\n",
       "    width: 32px;\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart:hover {\n",
       "    background-color: var(--hover-bg-color);\n",
       "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "    fill: var(--button-hover-fill-color);\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart-complete:disabled,\n",
       "  .colab-df-quickchart-complete:disabled:hover {\n",
       "    background-color: var(--disabled-bg-color);\n",
       "    fill: var(--disabled-fill-color);\n",
       "    box-shadow: none;\n",
       "  }\n",
       "\n",
       "  .colab-df-spinner {\n",
       "    border: 2px solid var(--fill-color);\n",
       "    border-color: transparent;\n",
       "    border-bottom-color: var(--fill-color);\n",
       "    animation:\n",
       "      spin 1s steps(1) infinite;\n",
       "  }\n",
       "\n",
       "  @keyframes spin {\n",
       "    0% {\n",
       "      border-color: transparent;\n",
       "      border-bottom-color: var(--fill-color);\n",
       "      border-left-color: var(--fill-color);\n",
       "    }\n",
       "    20% {\n",
       "      border-color: transparent;\n",
       "      border-left-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "    }\n",
       "    30% {\n",
       "      border-color: transparent;\n",
       "      border-left-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "      border-right-color: var(--fill-color);\n",
       "    }\n",
       "    40% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "    }\n",
       "    60% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "    }\n",
       "    80% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "      border-bottom-color: var(--fill-color);\n",
       "    }\n",
       "    90% {\n",
       "      border-color: transparent;\n",
       "      border-bottom-color: var(--fill-color);\n",
       "    }\n",
       "  }\n",
       "</style>\n",
       "\n",
       "  <script>\n",
       "    async function quickchart(key) {\n",
       "      const quickchartButtonEl =\n",
       "        document.querySelector('#' + key + ' button');\n",
       "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
       "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
       "      try {\n",
       "        const charts = await google.colab.kernel.invokeFunction(\n",
       "            'suggestCharts', [key], {});\n",
       "      } catch (error) {\n",
       "        console.error('Error during call to suggestCharts:', error);\n",
       "      }\n",
       "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
       "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
       "    }\n",
       "    (() => {\n",
       "      let quickchartButtonEl =\n",
       "        document.querySelector('#df-b394439c-c364-444d-9390-e0e00eec93bb button');\n",
       "      quickchartButtonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "    })();\n",
       "  </script>\n",
       "</div>\n",
       "    </div>\n",
       "  </div>\n"
      ],
      "text/plain": [
       "              y                                               text\n",
       "1875   negative  this t. rex dominates 'american ninja warrior'...\n",
       "11997  negative  computer science in vietnam: counting down to ...\n",
       "315    positive  dhs announces racial profiling free-for-all th...\n",
       "16252  negative   the best rent the runway dresses for bridesmaids\n",
       "12178  negative  abe's visit will remind americans china's powe...\n",
       "...         ...                                                ...\n",
       "10908  positive  sudden death of aunt creates rupture in family...\n",
       "17451  negative  over 50% of lgbtq youths struggle with eating ...\n",
       "16032  negative  gop senator: my family went from 'cotton to co...\n",
       "17823  negative  martin o'malley fails to make ohio's president...\n",
       "14495  positive  nra says parkland students should be grateful ...\n",
       "\n",
       "[22895 rows x 2 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "test_path = '/content/Sarcasm_Headlines_Dataset_v2.csv'\n",
    "train_df = pd.read_csv(test_path,sep=\",\")\n",
    "cols = [\"y\",\"text\"]\n",
    "train_df = train_df[cols]\n",
    "from sklearn.model_selection import train_test_split\n",
    "train_df, test_df = train_test_split(train_df, test_size=0.2)\n",
    "train_df\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "0296Om2C5anY"
   },
   "source": [
    "# 3. Train Deep Learning Classifier using nlu.load('train.sentiment')\n",
    "\n",
    "You dataset label column should be named 'y' and the feature column with text data should be named 'text'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "3ZIPkRkWftBG",
    "outputId": "d880ec91-023e-4f75-a687-94825d7ea1b5"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning::Spark Session already created, some configs may not take.\n",
      "sent_small_bert_L2_128 download started this may take some time.\n",
      "Approximate size to download 16.1 MB\n",
      "[OK!]\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "    negative       0.00      0.00      0.00        22\n",
      "    positive       0.56      1.00      0.72        28\n",
      "\n",
      "    accuracy                           0.56        50\n",
      "   macro avg       0.28      0.50      0.36        50\n",
      "weighted avg       0.31      0.56      0.40        50\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"df-b01ddae0-5e42-40b2-a053-38649bc33c7e\" class=\"colab-df-container\">\n",
       "    <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>document</th>\n",
       "      <th>sentence_embedding_small_bert_L2_128</th>\n",
       "      <th>sentiment</th>\n",
       "      <th>sentiment_confidence</th>\n",
       "      <th>text</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>kids in bus accident mocked by kids in passing...</td>\n",
       "      <td>[-0.7924436926841736, -0.07141707092523575, -0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>kids in bus accident mocked by kids in passing...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>these two words are stealing your freedom</td>\n",
       "      <td>[-1.028885006904602, -0.7214630246162415, 0.12...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>these two words are stealing your freedom</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>bush vows to do 'that thing gore just said, on...</td>\n",
       "      <td>[-1.7108917236328125, 0.2942552864551544, -0.3...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>bush vows to do 'that thing gore just said, on...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>scotland's parliament backs new independence r...</td>\n",
       "      <td>[0.14012272655963898, 0.7012102603912354, -0.0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>scotland's parliament backs new independence r...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>joe biden: being vice president is 'a bitch'</td>\n",
       "      <td>[-0.571045458316803, 0.5463784337043762, -0.17...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>joe biden: being vice president is 'a bitch'</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>u.s. army now just chasing single remaining is...</td>\n",
       "      <td>[-0.9116203188896179, -0.3868906497955322, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>u.s. army now just chasing single remaining is...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>sheryl crow's freshness date expires</td>\n",
       "      <td>[-1.388686180114746, 0.5200713872909546, -0.43...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>sheryl crow's freshness date expires</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>new ebola quarantine protocol seen as barrier ...</td>\n",
       "      <td>[-0.6295406222343445, 0.43973761796951294, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>new ebola quarantine protocol seen as barrier ...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>the secret to building a successful business t...</td>\n",
       "      <td>[-0.1442088484764099, 0.5362765192985535, -0.5...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>the secret to building a successful business t...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>school for crime</td>\n",
       "      <td>[-1.4345587491989136, 0.35326844453811646, -1....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>school for crime</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>want to increase trust? increase your say/do r...</td>\n",
       "      <td>[-1.2950726747512817, 1.153881311416626, -0.36...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>want to increase trust? increase your say/do r...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>when autocorrect and sexting collide</td>\n",
       "      <td>[-1.1433782577514648, 0.25382623076438904, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>when autocorrect and sexting collide</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>the house science committee doesn't seem to un...</td>\n",
       "      <td>[-0.24199619889259338, 0.8295924663543701, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>the house science committee doesn't seem to un...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>eric clapton wows audience with even slower ve...</td>\n",
       "      <td>[-0.12445597350597382, -0.2018168419599533, 0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>eric clapton wows audience with even slower ve...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>rick perry returning to iowa</td>\n",
       "      <td>[-1.3457694053649902, 0.5665305852890015, -0.5...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>rick perry returning to iowa</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>one beer can't do local alcoholic any harm</td>\n",
       "      <td>[-1.3927576541900635, 0.6284745335578918, -0.5...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>one beer can't do local alcoholic any harm</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>couple at point where they're comfortable usin...</td>\n",
       "      <td>[-1.5534732341766357, 0.2146364003419876, -0.6...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>couple at point where they're comfortable usin...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>watch how mountains of trash spread across the...</td>\n",
       "      <td>[-1.8412539958953857, 0.1492537260055542, -0.0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>watch how mountains of trash spread across the...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>lowly mortal opens portal to hell</td>\n",
       "      <td>[-0.8720283508300781, -1.011899709701538, -0.3...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>lowly mortal opens portal to hell</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>stephen hawking reportedly working on juicy te...</td>\n",
       "      <td>[-0.7349460124969482, -0.011331072077155113, 0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>stephen hawking reportedly working on juicy te...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>offshorers demand: no taxes, no risk</td>\n",
       "      <td>[-1.0823032855987549, 1.29856276512146, -0.915...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>offshorers demand: no taxes, no risk</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>troubling study finds majority of americans wh...</td>\n",
       "      <td>[-0.7015470862388611, -0.17110034823417664, -0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>troubling study finds majority of americans wh...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>annoying man more annoying after skydiving</td>\n",
       "      <td>[-1.4149224758148193, -1.0473958253860474, 0.1...</td>\n",
       "      <td>positive</td>\n",
       "      <td>6.0</td>\n",
       "      <td>annoying man more annoying after skydiving</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>robin hood foundation</td>\n",
       "      <td>[-0.057901788502931595, 0.8722413778305054, -0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>robin hood foundation</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>passenger glued to airplane window like it fuc...</td>\n",
       "      <td>[-0.33463752269744873, 0.7636221051216125, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>passenger glued to airplane window like it fuc...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>amazingly humanlike robot able to commit thous...</td>\n",
       "      <td>[-1.2185980081558228, -0.9673603177070618, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>amazingly humanlike robot able to commit thous...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>tourists describe scenes of horror in tunisian...</td>\n",
       "      <td>[-1.1378378868103027, -1.2116812467575073, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>tourists describe scenes of horror in tunisian...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>is your christmas present spying on you?</td>\n",
       "      <td>[-0.8687025308609009, -0.0924399271607399, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>is your christmas present spying on you?</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>area man busts his ass all day, and for what?</td>\n",
       "      <td>[-2.376340627670288, -0.3160030245780945, -0.4...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>area man busts his ass all day, and for what?</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>department of interior employee caught embezzl...</td>\n",
       "      <td>[-1.1687604188919067, 0.5776483416557312, -0.6...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>department of interior employee caught embezzl...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>new software yellows neglected digital photos ...</td>\n",
       "      <td>[-0.773508608341217, 0.5193011164665222, -0.54...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>new software yellows neglected digital photos ...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>read live updates on the cnn democratic debate</td>\n",
       "      <td>[-1.1500324010849, -0.5574671626091003, 0.3618...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>read live updates on the cnn democratic debate</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>new poultry stripe gum hardly tastes like goos...</td>\n",
       "      <td>[-1.2104802131652832, 0.2168104648590088, -0.0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>new poultry stripe gum hardly tastes like goos...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>new film takes an honest look at life with a t...</td>\n",
       "      <td>[-0.27279043197631836, -0.44589897990226746, -...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>new film takes an honest look at life with a t...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>vice president pence pushes expansive nato and...</td>\n",
       "      <td>[0.06816250830888748, 0.562971830368042, -0.57...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>vice president pence pushes expansive nato and...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>mom tucks handwritten guide on how to use netf...</td>\n",
       "      <td>[-1.1668932437896729, 0.6492086052894592, -0.3...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>mom tucks handwritten guide on how to use netf...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>man insists facebook friend actually reads 'wh...</td>\n",
       "      <td>[-0.41535136103630066, -0.6858690977096558, -0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>man insists facebook friend actually reads 'wh...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>internet explorer makes desperate overture to ...</td>\n",
       "      <td>[-0.058107126504182816, -0.19895373284816742, ...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>internet explorer makes desperate overture to ...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>rock song takes pro-rock stance</td>\n",
       "      <td>[-0.8466075658798218, -0.350190132856369, 0.33...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>rock song takes pro-rock stance</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>college still looking for absolute saddest pla...</td>\n",
       "      <td>[-0.8797492384910583, -0.09284910559654236, -0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>college still looking for absolute saddest pla...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>alton sterling's family demands action from ba...</td>\n",
       "      <td>[-1.123725175857544, 0.27766698598861694, -0.4...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>alton sterling's family demands action from ba...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>ronda rousey wants to show you how ripped she ...</td>\n",
       "      <td>[-0.704077959060669, 0.4832143783569336, -0.43...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>ronda rousey wants to show you how ripped she ...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>the workplace revolution: adding company cultu...</td>\n",
       "      <td>[-0.6472877860069275, 0.819389283657074, -0.50...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>the workplace revolution: adding company cultu...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>wolf blitzer walks into middle of olive garden...</td>\n",
       "      <td>[-1.089509129524231, -0.010750504210591316, -0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>wolf blitzer walks into middle of olive garden...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>grandchild, grandfather equally dreading colla...</td>\n",
       "      <td>[-0.9178588390350342, -0.05760730057954788, -0...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>grandchild, grandfather equally dreading colla...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>congress reassures nervous zuckerberg they won...</td>\n",
       "      <td>[-0.723938524723053, 0.5092206597328186, -0.02...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>congress reassures nervous zuckerberg they won...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>senators lured back to emergency session by pr...</td>\n",
       "      <td>[-2.088550567626953, 0.19368097186088562, -0.7...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>senators lured back to emergency session by pr...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>powerball officials remove plastic balls from ...</td>\n",
       "      <td>[-1.236419916152954, 0.6744992733001709, -0.52...</td>\n",
       "      <td>positive</td>\n",
       "      <td>9.0</td>\n",
       "      <td>powerball officials remove plastic balls from ...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>rude guy unfortunately says something funny</td>\n",
       "      <td>[-0.9946603775024414, -0.6593665480613708, 0.3...</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>rude guy unfortunately says something funny</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>the room i carry with me</td>\n",
       "      <td>[-1.4270148277282715, 0.47338584065437317, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.0</td>\n",
       "      <td>the room i carry with me</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "    <div class=\"colab-df-buttons\">\n",
       "\n",
       "  <div class=\"colab-df-container\">\n",
       "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-b01ddae0-5e42-40b2-a053-38649bc33c7e')\"\n",
       "            title=\"Convert this dataframe to an interactive table.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
       "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
       "  </svg>\n",
       "    </button>\n",
       "\n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    .colab-df-buttons div {\n",
       "      margin-bottom: 4px;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "    <script>\n",
       "      const buttonEl =\n",
       "        document.querySelector('#df-b01ddae0-5e42-40b2-a053-38649bc33c7e button.colab-df-convert');\n",
       "      buttonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "      async function convertToInteractive(key) {\n",
       "        const element = document.querySelector('#df-b01ddae0-5e42-40b2-a053-38649bc33c7e');\n",
       "        const dataTable =\n",
       "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                    [key], {});\n",
       "        if (!dataTable) return;\n",
       "\n",
       "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "          + ' to learn more about interactive tables.';\n",
       "        element.innerHTML = '';\n",
       "        dataTable['output_type'] = 'display_data';\n",
       "        await google.colab.output.renderOutput(dataTable, element);\n",
       "        const docLink = document.createElement('div');\n",
       "        docLink.innerHTML = docLinkHtml;\n",
       "        element.appendChild(docLink);\n",
       "      }\n",
       "    </script>\n",
       "  </div>\n",
       "\n",
       "\n",
       "<div id=\"df-e47a38b4-a4b2-4abf-9b92-c073e1276495\">\n",
       "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-e47a38b4-a4b2-4abf-9b92-c073e1276495')\"\n",
       "            title=\"Suggest charts.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "     width=\"24px\">\n",
       "    <g>\n",
       "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
       "    </g>\n",
       "</svg>\n",
       "  </button>\n",
       "\n",
       "<style>\n",
       "  .colab-df-quickchart {\n",
       "      --bg-color: #E8F0FE;\n",
       "      --fill-color: #1967D2;\n",
       "      --hover-bg-color: #E2EBFA;\n",
       "      --hover-fill-color: #174EA6;\n",
       "      --disabled-fill-color: #AAA;\n",
       "      --disabled-bg-color: #DDD;\n",
       "  }\n",
       "\n",
       "  [theme=dark] .colab-df-quickchart {\n",
       "      --bg-color: #3B4455;\n",
       "      --fill-color: #D2E3FC;\n",
       "      --hover-bg-color: #434B5C;\n",
       "      --hover-fill-color: #FFFFFF;\n",
       "      --disabled-bg-color: #3B4455;\n",
       "      --disabled-fill-color: #666;\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart {\n",
       "    background-color: var(--bg-color);\n",
       "    border: none;\n",
       "    border-radius: 50%;\n",
       "    cursor: pointer;\n",
       "    display: none;\n",
       "    fill: var(--fill-color);\n",
       "    height: 32px;\n",
       "    padding: 0;\n",
       "    width: 32px;\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart:hover {\n",
       "    background-color: var(--hover-bg-color);\n",
       "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "    fill: var(--button-hover-fill-color);\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart-complete:disabled,\n",
       "  .colab-df-quickchart-complete:disabled:hover {\n",
       "    background-color: var(--disabled-bg-color);\n",
       "    fill: var(--disabled-fill-color);\n",
       "    box-shadow: none;\n",
       "  }\n",
       "\n",
       "  .colab-df-spinner {\n",
       "    border: 2px solid var(--fill-color);\n",
       "    border-color: transparent;\n",
       "    border-bottom-color: var(--fill-color);\n",
       "    animation:\n",
       "      spin 1s steps(1) infinite;\n",
       "  }\n",
       "\n",
       "  @keyframes spin {\n",
       "    0% {\n",
       "      border-color: transparent;\n",
       "      border-bottom-color: var(--fill-color);\n",
       "      border-left-color: var(--fill-color);\n",
       "    }\n",
       "    20% {\n",
       "      border-color: transparent;\n",
       "      border-left-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "    }\n",
       "    30% {\n",
       "      border-color: transparent;\n",
       "      border-left-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "      border-right-color: var(--fill-color);\n",
       "    }\n",
       "    40% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "    }\n",
       "    60% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "    }\n",
       "    80% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "      border-bottom-color: var(--fill-color);\n",
       "    }\n",
       "    90% {\n",
       "      border-color: transparent;\n",
       "      border-bottom-color: var(--fill-color);\n",
       "    }\n",
       "  }\n",
       "</style>\n",
       "\n",
       "  <script>\n",
       "    async function quickchart(key) {\n",
       "      const quickchartButtonEl =\n",
       "        document.querySelector('#' + key + ' button');\n",
       "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
       "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
       "      try {\n",
       "        const charts = await google.colab.kernel.invokeFunction(\n",
       "            'suggestCharts', [key], {});\n",
       "      } catch (error) {\n",
       "        console.error('Error during call to suggestCharts:', error);\n",
       "      }\n",
       "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
       "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
       "    }\n",
       "    (() => {\n",
       "      let quickchartButtonEl =\n",
       "        document.querySelector('#df-e47a38b4-a4b2-4abf-9b92-c073e1276495 button');\n",
       "      quickchartButtonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "    })();\n",
       "  </script>\n",
       "</div>\n",
       "    </div>\n",
       "  </div>\n"
      ],
      "text/plain": [
       "                                             document  \\\n",
       "0   kids in bus accident mocked by kids in passing...   \n",
       "1           these two words are stealing your freedom   \n",
       "2   bush vows to do 'that thing gore just said, on...   \n",
       "3   scotland's parliament backs new independence r...   \n",
       "4        joe biden: being vice president is 'a bitch'   \n",
       "5   u.s. army now just chasing single remaining is...   \n",
       "6                sheryl crow's freshness date expires   \n",
       "7   new ebola quarantine protocol seen as barrier ...   \n",
       "8   the secret to building a successful business t...   \n",
       "9                                    school for crime   \n",
       "10  want to increase trust? increase your say/do r...   \n",
       "11               when autocorrect and sexting collide   \n",
       "12  the house science committee doesn't seem to un...   \n",
       "13  eric clapton wows audience with even slower ve...   \n",
       "14                       rick perry returning to iowa   \n",
       "15         one beer can't do local alcoholic any harm   \n",
       "16  couple at point where they're comfortable usin...   \n",
       "17  watch how mountains of trash spread across the...   \n",
       "18                  lowly mortal opens portal to hell   \n",
       "19  stephen hawking reportedly working on juicy te...   \n",
       "20               offshorers demand: no taxes, no risk   \n",
       "21  troubling study finds majority of americans wh...   \n",
       "22         annoying man more annoying after skydiving   \n",
       "23                              robin hood foundation   \n",
       "24  passenger glued to airplane window like it fuc...   \n",
       "25  amazingly humanlike robot able to commit thous...   \n",
       "26  tourists describe scenes of horror in tunisian...   \n",
       "27           is your christmas present spying on you?   \n",
       "28      area man busts his ass all day, and for what?   \n",
       "29  department of interior employee caught embezzl...   \n",
       "30  new software yellows neglected digital photos ...   \n",
       "31     read live updates on the cnn democratic debate   \n",
       "32  new poultry stripe gum hardly tastes like goos...   \n",
       "33  new film takes an honest look at life with a t...   \n",
       "34  vice president pence pushes expansive nato and...   \n",
       "35  mom tucks handwritten guide on how to use netf...   \n",
       "36  man insists facebook friend actually reads 'wh...   \n",
       "37  internet explorer makes desperate overture to ...   \n",
       "38                    rock song takes pro-rock stance   \n",
       "39  college still looking for absolute saddest pla...   \n",
       "40  alton sterling's family demands action from ba...   \n",
       "41  ronda rousey wants to show you how ripped she ...   \n",
       "42  the workplace revolution: adding company cultu...   \n",
       "43  wolf blitzer walks into middle of olive garden...   \n",
       "44  grandchild, grandfather equally dreading colla...   \n",
       "45  congress reassures nervous zuckerberg they won...   \n",
       "46  senators lured back to emergency session by pr...   \n",
       "47  powerball officials remove plastic balls from ...   \n",
       "48        rude guy unfortunately says something funny   \n",
       "49                           the room i carry with me   \n",
       "\n",
       "                 sentence_embedding_small_bert_L2_128 sentiment  \\\n",
       "0   [-0.7924436926841736, -0.07141707092523575, -0...  positive   \n",
       "1   [-1.028885006904602, -0.7214630246162415, 0.12...  positive   \n",
       "2   [-1.7108917236328125, 0.2942552864551544, -0.3...  positive   \n",
       "3   [0.14012272655963898, 0.7012102603912354, -0.0...  positive   \n",
       "4   [-0.571045458316803, 0.5463784337043762, -0.17...  positive   \n",
       "5   [-0.9116203188896179, -0.3868906497955322, -0....  positive   \n",
       "6   [-1.388686180114746, 0.5200713872909546, -0.43...  positive   \n",
       "7   [-0.6295406222343445, 0.43973761796951294, -0....  positive   \n",
       "8   [-0.1442088484764099, 0.5362765192985535, -0.5...  positive   \n",
       "9   [-1.4345587491989136, 0.35326844453811646, -1....  positive   \n",
       "10  [-1.2950726747512817, 1.153881311416626, -0.36...  positive   \n",
       "11  [-1.1433782577514648, 0.25382623076438904, -0....  positive   \n",
       "12  [-0.24199619889259338, 0.8295924663543701, -0....  positive   \n",
       "13  [-0.12445597350597382, -0.2018168419599533, 0....  positive   \n",
       "14  [-1.3457694053649902, 0.5665305852890015, -0.5...  positive   \n",
       "15  [-1.3927576541900635, 0.6284745335578918, -0.5...  positive   \n",
       "16  [-1.5534732341766357, 0.2146364003419876, -0.6...  positive   \n",
       "17  [-1.8412539958953857, 0.1492537260055542, -0.0...  positive   \n",
       "18  [-0.8720283508300781, -1.011899709701538, -0.3...  positive   \n",
       "19  [-0.7349460124969482, -0.011331072077155113, 0...  positive   \n",
       "20  [-1.0823032855987549, 1.29856276512146, -0.915...  positive   \n",
       "21  [-0.7015470862388611, -0.17110034823417664, -0...  positive   \n",
       "22  [-1.4149224758148193, -1.0473958253860474, 0.1...  positive   \n",
       "23  [-0.057901788502931595, 0.8722413778305054, -0...  positive   \n",
       "24  [-0.33463752269744873, 0.7636221051216125, -0....  positive   \n",
       "25  [-1.2185980081558228, -0.9673603177070618, -0....  positive   \n",
       "26  [-1.1378378868103027, -1.2116812467575073, -0....  positive   \n",
       "27  [-0.8687025308609009, -0.0924399271607399, -0....  positive   \n",
       "28  [-2.376340627670288, -0.3160030245780945, -0.4...  positive   \n",
       "29  [-1.1687604188919067, 0.5776483416557312, -0.6...  positive   \n",
       "30  [-0.773508608341217, 0.5193011164665222, -0.54...  positive   \n",
       "31  [-1.1500324010849, -0.5574671626091003, 0.3618...  positive   \n",
       "32  [-1.2104802131652832, 0.2168104648590088, -0.0...  positive   \n",
       "33  [-0.27279043197631836, -0.44589897990226746, -...  positive   \n",
       "34  [0.06816250830888748, 0.562971830368042, -0.57...  positive   \n",
       "35  [-1.1668932437896729, 0.6492086052894592, -0.3...  positive   \n",
       "36  [-0.41535136103630066, -0.6858690977096558, -0...  positive   \n",
       "37  [-0.058107126504182816, -0.19895373284816742, ...  positive   \n",
       "38  [-0.8466075658798218, -0.350190132856369, 0.33...  positive   \n",
       "39  [-0.8797492384910583, -0.09284910559654236, -0...  positive   \n",
       "40  [-1.123725175857544, 0.27766698598861694, -0.4...  positive   \n",
       "41  [-0.704077959060669, 0.4832143783569336, -0.43...  positive   \n",
       "42  [-0.6472877860069275, 0.819389283657074, -0.50...  positive   \n",
       "43  [-1.089509129524231, -0.010750504210591316, -0...  positive   \n",
       "44  [-0.9178588390350342, -0.05760730057954788, -0...  positive   \n",
       "45  [-0.723938524723053, 0.5092206597328186, -0.02...  positive   \n",
       "46  [-2.088550567626953, 0.19368097186088562, -0.7...  positive   \n",
       "47  [-1.236419916152954, 0.6744992733001709, -0.52...  positive   \n",
       "48  [-0.9946603775024414, -0.6593665480613708, 0.3...  positive   \n",
       "49  [-1.4270148277282715, 0.47338584065437317, -0....  positive   \n",
       "\n",
       "   sentiment_confidence                                               text  \\\n",
       "0                   0.0  kids in bus accident mocked by kids in passing...   \n",
       "1                   0.0          these two words are stealing your freedom   \n",
       "2                   0.0  bush vows to do 'that thing gore just said, on...   \n",
       "3                   0.0  scotland's parliament backs new independence r...   \n",
       "4                   0.0       joe biden: being vice president is 'a bitch'   \n",
       "5                   0.0  u.s. army now just chasing single remaining is...   \n",
       "6                   0.0               sheryl crow's freshness date expires   \n",
       "7                   0.0  new ebola quarantine protocol seen as barrier ...   \n",
       "8                   0.0  the secret to building a successful business t...   \n",
       "9                   0.0                                   school for crime   \n",
       "10                  0.0  want to increase trust? increase your say/do r...   \n",
       "11                  0.0               when autocorrect and sexting collide   \n",
       "12                  0.0  the house science committee doesn't seem to un...   \n",
       "13                  0.0  eric clapton wows audience with even slower ve...   \n",
       "14                  0.0                       rick perry returning to iowa   \n",
       "15                  0.0         one beer can't do local alcoholic any harm   \n",
       "16                  0.0  couple at point where they're comfortable usin...   \n",
       "17                  0.0  watch how mountains of trash spread across the...   \n",
       "18                  0.0                  lowly mortal opens portal to hell   \n",
       "19                  0.0  stephen hawking reportedly working on juicy te...   \n",
       "20                  0.0               offshorers demand: no taxes, no risk   \n",
       "21                  0.0  troubling study finds majority of americans wh...   \n",
       "22                  6.0         annoying man more annoying after skydiving   \n",
       "23                  0.0                              robin hood foundation   \n",
       "24                  0.0  passenger glued to airplane window like it fuc...   \n",
       "25                  0.0  amazingly humanlike robot able to commit thous...   \n",
       "26                  0.0  tourists describe scenes of horror in tunisian...   \n",
       "27                  0.0           is your christmas present spying on you?   \n",
       "28                  0.0      area man busts his ass all day, and for what?   \n",
       "29                  0.0  department of interior employee caught embezzl...   \n",
       "30                  0.0  new software yellows neglected digital photos ...   \n",
       "31                  0.0     read live updates on the cnn democratic debate   \n",
       "32                  0.0  new poultry stripe gum hardly tastes like goos...   \n",
       "33                  0.0  new film takes an honest look at life with a t...   \n",
       "34                  0.0  vice president pence pushes expansive nato and...   \n",
       "35                  0.0  mom tucks handwritten guide on how to use netf...   \n",
       "36                  0.0  man insists facebook friend actually reads 'wh...   \n",
       "37                  0.0  internet explorer makes desperate overture to ...   \n",
       "38                  0.0                    rock song takes pro-rock stance   \n",
       "39                  0.0  college still looking for absolute saddest pla...   \n",
       "40                  0.0  alton sterling's family demands action from ba...   \n",
       "41                  0.0  ronda rousey wants to show you how ripped she ...   \n",
       "42                  0.0  the workplace revolution: adding company cultu...   \n",
       "43                  0.0  wolf blitzer walks into middle of olive garden...   \n",
       "44                  0.0  grandchild, grandfather equally dreading colla...   \n",
       "45                  0.0  congress reassures nervous zuckerberg they won...   \n",
       "46                  0.0  senators lured back to emergency session by pr...   \n",
       "47                  9.0  powerball officials remove plastic balls from ...   \n",
       "48                  0.0        rude guy unfortunately says something funny   \n",
       "49                  0.0                           the room i carry with me   \n",
       "\n",
       "           y  \n",
       "0   positive  \n",
       "1   negative  \n",
       "2   positive  \n",
       "3   negative  \n",
       "4   negative  \n",
       "5   positive  \n",
       "6   positive  \n",
       "7   negative  \n",
       "8   negative  \n",
       "9   negative  \n",
       "10  negative  \n",
       "11  negative  \n",
       "12  negative  \n",
       "13  positive  \n",
       "14  negative  \n",
       "15  positive  \n",
       "16  positive  \n",
       "17  negative  \n",
       "18  positive  \n",
       "19  positive  \n",
       "20  negative  \n",
       "21  positive  \n",
       "22  positive  \n",
       "23  negative  \n",
       "24  positive  \n",
       "25  positive  \n",
       "26  negative  \n",
       "27  negative  \n",
       "28  positive  \n",
       "29  positive  \n",
       "30  positive  \n",
       "31  negative  \n",
       "32  positive  \n",
       "33  negative  \n",
       "34  negative  \n",
       "35  positive  \n",
       "36  positive  \n",
       "37  positive  \n",
       "38  positive  \n",
       "39  positive  \n",
       "40  negative  \n",
       "41  negative  \n",
       "42  negative  \n",
       "43  positive  \n",
       "44  positive  \n",
       "45  positive  \n",
       "46  positive  \n",
       "47  positive  \n",
       "48  positive  \n",
       "49  negative  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from johnsnowlabs import nlp\n",
    "from sklearn.metrics import classification_report\n",
    "\n",
    "# load a trainable pipeline by specifying the train. prefix  and fit it on a datset with label and text columns\n",
    "# by default the Universal Sentence Encoder (USE) Sentence embeddings are used for generation\n",
    "trainable_pipe = nlp.load('train.sentiment')\n",
    "fitted_pipe = trainable_pipe.fit(train_df.iloc[:50])\n",
    "\n",
    "# predict with the trainable pipeline on dataset and get predictions\n",
    "preds = fitted_pipe.predict(train_df.iloc[:50],output_level='document')\n",
    "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
    "preds.dropna(inplace=True)\n",
    "\n",
    "print(classification_report(preds['y'], preds['sentiment']))\n",
    "\n",
    "preds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "lVyOE2wV0fw_"
   },
   "source": [
    "# 4. Test the fitted pipe on new example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 150
    },
    "id": "qdCUg2MR0PD2",
    "outputId": "dd1009b1-8146-4cfa-8be5-b9ab14e444ec"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sentence_detector_dl download started this may take some time.\n",
      "Approximate size to download 354.6 KB\n",
      "[OK!]\n",
      "Warning::Spark Session already created, some configs may not take.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"df-568b7040-5507-4877-9a6f-d2f1e5aca97b\" class=\"colab-df-container\">\n",
       "    <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sentence</th>\n",
       "      <th>sentence_embedding_small_bert_L2_128</th>\n",
       "      <th>sentiment</th>\n",
       "      <th>sentiment_confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Aliens are immortal!</td>\n",
       "      <td>[-0.6534902453422546, -1.4232430458068848, -0....</td>\n",
       "      <td>positive</td>\n",
       "      <td>0.989048</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "    <div class=\"colab-df-buttons\">\n",
       "\n",
       "  <div class=\"colab-df-container\">\n",
       "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-568b7040-5507-4877-9a6f-d2f1e5aca97b')\"\n",
       "            title=\"Convert this dataframe to an interactive table.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
       "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
       "  </svg>\n",
       "    </button>\n",
       "\n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    .colab-df-buttons div {\n",
       "      margin-bottom: 4px;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "    <script>\n",
       "      const buttonEl =\n",
       "        document.querySelector('#df-568b7040-5507-4877-9a6f-d2f1e5aca97b button.colab-df-convert');\n",
       "      buttonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "      async function convertToInteractive(key) {\n",
       "        const element = document.querySelector('#df-568b7040-5507-4877-9a6f-d2f1e5aca97b');\n",
       "        const dataTable =\n",
       "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                    [key], {});\n",
       "        if (!dataTable) return;\n",
       "\n",
       "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "          + ' to learn more about interactive tables.';\n",
       "        element.innerHTML = '';\n",
       "        dataTable['output_type'] = 'display_data';\n",
       "        await google.colab.output.renderOutput(dataTable, element);\n",
       "        const docLink = document.createElement('div');\n",
       "        docLink.innerHTML = docLinkHtml;\n",
       "        element.appendChild(docLink);\n",
       "      }\n",
       "    </script>\n",
       "  </div>\n",
       "\n",
       "    </div>\n",
       "  </div>\n"
      ],
      "text/plain": [
       "               sentence               sentence_embedding_small_bert_L2_128  \\\n",
       "0  Aliens are immortal!  [-0.6534902453422546, -1.4232430458068848, -0....   \n",
       "\n",
       "  sentiment sentiment_confidence  \n",
       "0  positive             0.989048  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fitted_pipe.predict('Aliens are immortal!')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "xflpwrVjjBVD"
   },
   "source": [
    "## 5. Configure pipe training parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "UtsAUGTmOTms",
    "outputId": "9977460e-1f6e-497a-ca9c-2d78957f7aa2"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The following parameters are configurable for this NLU pipeline (You can copy paste the examples) :\n",
      ">>> component_list['bert_sentence_embeddings@sent_small_bert_L2_128'] has settable params:\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setBatchSize(8)              | Info: Size of every batch | Currently set to : 8\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setEngine('tensorflow')      | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setIsLong(False)             | Info: Use Long type instead of Int type for inputs buffer - Some Bert models require Long instead of Int. | Currently set to : False\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setMaxSentenceLength(128)    | Info: Max sentence length to process | Currently set to : 128\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setDimension(128)            | Info: Number of embedding dimensions | Currently set to : 128\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setCaseSensitive(False)      | Info: whether to ignore case in tokens for embeddings matching | Currently set to : False\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setStorageRef('sent_small_bert_L2_128')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L2_128\n",
      ">>> component_list['document_assembler'] has settable params:\n",
      "component_list['document_assembler'].setCleanupMode('shrink')                                  | Info: possible values: disabled, inplace, inplace_full, shrink, shrink_full, each, each_full, delete_full | Currently set to : shrink\n",
      ">>> component_list['sentiment_dl@sent_small_bert_L2_128'] has settable params:\n",
      "component_list['sentiment_dl@sent_small_bert_L2_128'].setEngine('tensorflow')                  | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
      "component_list['sentiment_dl@sent_small_bert_L2_128'].setThreshold(0.6)                        | Info: The minimum threshold for the final result otheriwse it will be neutral | Currently set to : 0.6\n",
      "component_list['sentiment_dl@sent_small_bert_L2_128'].setThresholdLabel('neutral')             | Info: In case the score is less than threshold, what should be the label. Default is neutral. | Currently set to : neutral\n",
      "component_list['sentiment_dl@sent_small_bert_L2_128'].setStorageRef('sent_small_bert_L2_128')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L2_128\n"
     ]
    }
   ],
   "source": [
    "trainable_pipe.print_info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "2GJdDNV9jEIe"
   },
   "source": [
    "## 6. Retrain with new parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "mptfvHx-MMMX",
    "outputId": "2a8a4c62-02a1-48d4-8331-990e1268c030"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning::Spark Session already created, some configs may not take.\n",
      "Warning::Spark Session already created, some configs may not take.\n",
      "sent_small_bert_L2_128 download started this may take some time.\n",
      "Approximate size to download 16.1 MB\n",
      "[OK!]\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "    negative       0.44      1.00      0.61        22\n",
      "    positive       0.00      0.00      0.00        28\n",
      "\n",
      "    accuracy                           0.44        50\n",
      "   macro avg       0.22      0.50      0.31        50\n",
      "weighted avg       0.19      0.44      0.27        50\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"df-105df12c-d258-451b-acdb-4bb7615b5aaa\" class=\"colab-df-container\">\n",
       "    <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>document</th>\n",
       "      <th>sentence_embedding_small_bert_L2_128</th>\n",
       "      <th>sentiment</th>\n",
       "      <th>sentiment_confidence</th>\n",
       "      <th>text</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>kids in bus accident mocked by kids in passing...</td>\n",
       "      <td>[-0.7924436926841736, -0.07141707092523575, -0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>7.0</td>\n",
       "      <td>kids in bus accident mocked by kids in passing...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>these two words are stealing your freedom</td>\n",
       "      <td>[-1.028885006904602, -0.7214630246162415, 0.12...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>these two words are stealing your freedom</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>bush vows to do 'that thing gore just said, on...</td>\n",
       "      <td>[-1.7108917236328125, 0.2942552864551544, -0.3...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>bush vows to do 'that thing gore just said, on...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>scotland's parliament backs new independence r...</td>\n",
       "      <td>[0.14012272655963898, 0.7012102603912354, -0.0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>5.0</td>\n",
       "      <td>scotland's parliament backs new independence r...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>joe biden: being vice president is 'a bitch'</td>\n",
       "      <td>[-0.571045458316803, 0.5463784337043762, -0.17...</td>\n",
       "      <td>negative</td>\n",
       "      <td>2.0</td>\n",
       "      <td>joe biden: being vice president is 'a bitch'</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>u.s. army now just chasing single remaining is...</td>\n",
       "      <td>[-0.9116203188896179, -0.3868906497955322, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>u.s. army now just chasing single remaining is...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>sheryl crow's freshness date expires</td>\n",
       "      <td>[-1.388686180114746, 0.5200713872909546, -0.43...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>sheryl crow's freshness date expires</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>new ebola quarantine protocol seen as barrier ...</td>\n",
       "      <td>[-0.6295406222343445, 0.43973761796951294, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>new ebola quarantine protocol seen as barrier ...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>the secret to building a successful business t...</td>\n",
       "      <td>[-0.1442088484764099, 0.5362765192985535, -0.5...</td>\n",
       "      <td>negative</td>\n",
       "      <td>4.0</td>\n",
       "      <td>the secret to building a successful business t...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>school for crime</td>\n",
       "      <td>[-1.4345587491989136, 0.35326844453811646, -1....</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>school for crime</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>want to increase trust? increase your say/do r...</td>\n",
       "      <td>[-1.2950726747512817, 1.153881311416626, -0.36...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>want to increase trust? increase your say/do r...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>when autocorrect and sexting collide</td>\n",
       "      <td>[-1.1433782577514648, 0.25382623076438904, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>when autocorrect and sexting collide</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>the house science committee doesn't seem to un...</td>\n",
       "      <td>[-0.24199619889259338, 0.8295924663543701, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>7.0</td>\n",
       "      <td>the house science committee doesn't seem to un...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>eric clapton wows audience with even slower ve...</td>\n",
       "      <td>[-0.12445597350597382, -0.2018168419599533, 0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>6.0</td>\n",
       "      <td>eric clapton wows audience with even slower ve...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>rick perry returning to iowa</td>\n",
       "      <td>[-1.3457694053649902, 0.5665305852890015, -0.5...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>rick perry returning to iowa</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>one beer can't do local alcoholic any harm</td>\n",
       "      <td>[-1.3927576541900635, 0.6284745335578918, -0.5...</td>\n",
       "      <td>negative</td>\n",
       "      <td>6.0</td>\n",
       "      <td>one beer can't do local alcoholic any harm</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>couple at point where they're comfortable usin...</td>\n",
       "      <td>[-1.5534732341766357, 0.2146364003419876, -0.6...</td>\n",
       "      <td>negative</td>\n",
       "      <td>2.0</td>\n",
       "      <td>couple at point where they're comfortable usin...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>watch how mountains of trash spread across the...</td>\n",
       "      <td>[-1.8412539958953857, 0.1492537260055542, -0.0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>4.0</td>\n",
       "      <td>watch how mountains of trash spread across the...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>lowly mortal opens portal to hell</td>\n",
       "      <td>[-0.8720283508300781, -1.011899709701538, -0.3...</td>\n",
       "      <td>negative</td>\n",
       "      <td>6.0</td>\n",
       "      <td>lowly mortal opens portal to hell</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>stephen hawking reportedly working on juicy te...</td>\n",
       "      <td>[-0.7349460124969482, -0.011331072077155113, 0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>5.0</td>\n",
       "      <td>stephen hawking reportedly working on juicy te...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>offshorers demand: no taxes, no risk</td>\n",
       "      <td>[-1.0823032855987549, 1.29856276512146, -0.915...</td>\n",
       "      <td>negative</td>\n",
       "      <td>2.0</td>\n",
       "      <td>offshorers demand: no taxes, no risk</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>troubling study finds majority of americans wh...</td>\n",
       "      <td>[-0.7015470862388611, -0.17110034823417664, -0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>5.0</td>\n",
       "      <td>troubling study finds majority of americans wh...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>annoying man more annoying after skydiving</td>\n",
       "      <td>[-1.4149224758148193, -1.0473958253860474, 0.1...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>annoying man more annoying after skydiving</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>robin hood foundation</td>\n",
       "      <td>[-0.057901788502931595, 0.8722413778305054, -0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>6.0</td>\n",
       "      <td>robin hood foundation</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>passenger glued to airplane window like it fuc...</td>\n",
       "      <td>[-0.33463752269744873, 0.7636221051216125, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>passenger glued to airplane window like it fuc...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>amazingly humanlike robot able to commit thous...</td>\n",
       "      <td>[-1.2185980081558228, -0.9673603177070618, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>3.0</td>\n",
       "      <td>amazingly humanlike robot able to commit thous...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>tourists describe scenes of horror in tunisian...</td>\n",
       "      <td>[-1.1378378868103027, -1.2116812467575073, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>5.0</td>\n",
       "      <td>tourists describe scenes of horror in tunisian...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>is your christmas present spying on you?</td>\n",
       "      <td>[-0.8687025308609009, -0.0924399271607399, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>3.0</td>\n",
       "      <td>is your christmas present spying on you?</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>area man busts his ass all day, and for what?</td>\n",
       "      <td>[-2.376340627670288, -0.3160030245780945, -0.4...</td>\n",
       "      <td>negative</td>\n",
       "      <td>5.0</td>\n",
       "      <td>area man busts his ass all day, and for what?</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>department of interior employee caught embezzl...</td>\n",
       "      <td>[-1.1687604188919067, 0.5776483416557312, -0.6...</td>\n",
       "      <td>negative</td>\n",
       "      <td>2.0</td>\n",
       "      <td>department of interior employee caught embezzl...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>new software yellows neglected digital photos ...</td>\n",
       "      <td>[-0.773508608341217, 0.5193011164665222, -0.54...</td>\n",
       "      <td>negative</td>\n",
       "      <td>9.0</td>\n",
       "      <td>new software yellows neglected digital photos ...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>read live updates on the cnn democratic debate</td>\n",
       "      <td>[-1.1500324010849, -0.5574671626091003, 0.3618...</td>\n",
       "      <td>negative</td>\n",
       "      <td>8.0</td>\n",
       "      <td>read live updates on the cnn democratic debate</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>new poultry stripe gum hardly tastes like goos...</td>\n",
       "      <td>[-1.2104802131652832, 0.2168104648590088, -0.0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>new poultry stripe gum hardly tastes like goos...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>new film takes an honest look at life with a t...</td>\n",
       "      <td>[-0.27279043197631836, -0.44589897990226746, -...</td>\n",
       "      <td>negative</td>\n",
       "      <td>4.0</td>\n",
       "      <td>new film takes an honest look at life with a t...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>vice president pence pushes expansive nato and...</td>\n",
       "      <td>[0.06816250830888748, 0.562971830368042, -0.57...</td>\n",
       "      <td>negative</td>\n",
       "      <td>3.0</td>\n",
       "      <td>vice president pence pushes expansive nato and...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>mom tucks handwritten guide on how to use netf...</td>\n",
       "      <td>[-1.1668932437896729, 0.6492086052894592, -0.3...</td>\n",
       "      <td>negative</td>\n",
       "      <td>2.0</td>\n",
       "      <td>mom tucks handwritten guide on how to use netf...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>man insists facebook friend actually reads 'wh...</td>\n",
       "      <td>[-0.41535136103630066, -0.6858690977096558, -0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>7.0</td>\n",
       "      <td>man insists facebook friend actually reads 'wh...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>internet explorer makes desperate overture to ...</td>\n",
       "      <td>[-0.058107126504182816, -0.19895373284816742, ...</td>\n",
       "      <td>negative</td>\n",
       "      <td>2.0</td>\n",
       "      <td>internet explorer makes desperate overture to ...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>rock song takes pro-rock stance</td>\n",
       "      <td>[-0.8466075658798218, -0.350190132856369, 0.33...</td>\n",
       "      <td>negative</td>\n",
       "      <td>4.0</td>\n",
       "      <td>rock song takes pro-rock stance</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>college still looking for absolute saddest pla...</td>\n",
       "      <td>[-0.8797492384910583, -0.09284910559654236, -0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>9.0</td>\n",
       "      <td>college still looking for absolute saddest pla...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>alton sterling's family demands action from ba...</td>\n",
       "      <td>[-1.123725175857544, 0.27766698598861694, -0.4...</td>\n",
       "      <td>negative</td>\n",
       "      <td>3.0</td>\n",
       "      <td>alton sterling's family demands action from ba...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>ronda rousey wants to show you how ripped she ...</td>\n",
       "      <td>[-0.704077959060669, 0.4832143783569336, -0.43...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>ronda rousey wants to show you how ripped she ...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>the workplace revolution: adding company cultu...</td>\n",
       "      <td>[-0.6472877860069275, 0.819389283657074, -0.50...</td>\n",
       "      <td>negative</td>\n",
       "      <td>2.0</td>\n",
       "      <td>the workplace revolution: adding company cultu...</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>wolf blitzer walks into middle of olive garden...</td>\n",
       "      <td>[-1.089509129524231, -0.010750504210591316, -0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>wolf blitzer walks into middle of olive garden...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>grandchild, grandfather equally dreading colla...</td>\n",
       "      <td>[-0.9178588390350342, -0.05760730057954788, -0...</td>\n",
       "      <td>negative</td>\n",
       "      <td>4.0</td>\n",
       "      <td>grandchild, grandfather equally dreading colla...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>congress reassures nervous zuckerberg they won...</td>\n",
       "      <td>[-0.723938524723053, 0.5092206597328186, -0.02...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>congress reassures nervous zuckerberg they won...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>senators lured back to emergency session by pr...</td>\n",
       "      <td>[-2.088550567626953, 0.19368097186088562, -0.7...</td>\n",
       "      <td>negative</td>\n",
       "      <td>3.0</td>\n",
       "      <td>senators lured back to emergency session by pr...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>powerball officials remove plastic balls from ...</td>\n",
       "      <td>[-1.236419916152954, 0.6744992733001709, -0.52...</td>\n",
       "      <td>negative</td>\n",
       "      <td>1.0</td>\n",
       "      <td>powerball officials remove plastic balls from ...</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>rude guy unfortunately says something funny</td>\n",
       "      <td>[-0.9946603775024414, -0.6593665480613708, 0.3...</td>\n",
       "      <td>negative</td>\n",
       "      <td>6.0</td>\n",
       "      <td>rude guy unfortunately says something funny</td>\n",
       "      <td>positive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>the room i carry with me</td>\n",
       "      <td>[-1.4270148277282715, 0.47338584065437317, -0....</td>\n",
       "      <td>negative</td>\n",
       "      <td>4.0</td>\n",
       "      <td>the room i carry with me</td>\n",
       "      <td>negative</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "    <div class=\"colab-df-buttons\">\n",
       "\n",
       "  <div class=\"colab-df-container\">\n",
       "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-105df12c-d258-451b-acdb-4bb7615b5aaa')\"\n",
       "            title=\"Convert this dataframe to an interactive table.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
       "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
       "  </svg>\n",
       "    </button>\n",
       "\n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    .colab-df-buttons div {\n",
       "      margin-bottom: 4px;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "    <script>\n",
       "      const buttonEl =\n",
       "        document.querySelector('#df-105df12c-d258-451b-acdb-4bb7615b5aaa button.colab-df-convert');\n",
       "      buttonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "      async function convertToInteractive(key) {\n",
       "        const element = document.querySelector('#df-105df12c-d258-451b-acdb-4bb7615b5aaa');\n",
       "        const dataTable =\n",
       "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                    [key], {});\n",
       "        if (!dataTable) return;\n",
       "\n",
       "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "          + ' to learn more about interactive tables.';\n",
       "        element.innerHTML = '';\n",
       "        dataTable['output_type'] = 'display_data';\n",
       "        await google.colab.output.renderOutput(dataTable, element);\n",
       "        const docLink = document.createElement('div');\n",
       "        docLink.innerHTML = docLinkHtml;\n",
       "        element.appendChild(docLink);\n",
       "      }\n",
       "    </script>\n",
       "  </div>\n",
       "\n",
       "\n",
       "<div id=\"df-aa396d9e-3333-4c90-8cd8-a8e6421bd114\">\n",
       "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-aa396d9e-3333-4c90-8cd8-a8e6421bd114')\"\n",
       "            title=\"Suggest charts.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "     width=\"24px\">\n",
       "    <g>\n",
       "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
       "    </g>\n",
       "</svg>\n",
       "  </button>\n",
       "\n",
       "<style>\n",
       "  .colab-df-quickchart {\n",
       "      --bg-color: #E8F0FE;\n",
       "      --fill-color: #1967D2;\n",
       "      --hover-bg-color: #E2EBFA;\n",
       "      --hover-fill-color: #174EA6;\n",
       "      --disabled-fill-color: #AAA;\n",
       "      --disabled-bg-color: #DDD;\n",
       "  }\n",
       "\n",
       "  [theme=dark] .colab-df-quickchart {\n",
       "      --bg-color: #3B4455;\n",
       "      --fill-color: #D2E3FC;\n",
       "      --hover-bg-color: #434B5C;\n",
       "      --hover-fill-color: #FFFFFF;\n",
       "      --disabled-bg-color: #3B4455;\n",
       "      --disabled-fill-color: #666;\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart {\n",
       "    background-color: var(--bg-color);\n",
       "    border: none;\n",
       "    border-radius: 50%;\n",
       "    cursor: pointer;\n",
       "    display: none;\n",
       "    fill: var(--fill-color);\n",
       "    height: 32px;\n",
       "    padding: 0;\n",
       "    width: 32px;\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart:hover {\n",
       "    background-color: var(--hover-bg-color);\n",
       "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "    fill: var(--button-hover-fill-color);\n",
       "  }\n",
       "\n",
       "  .colab-df-quickchart-complete:disabled,\n",
       "  .colab-df-quickchart-complete:disabled:hover {\n",
       "    background-color: var(--disabled-bg-color);\n",
       "    fill: var(--disabled-fill-color);\n",
       "    box-shadow: none;\n",
       "  }\n",
       "\n",
       "  .colab-df-spinner {\n",
       "    border: 2px solid var(--fill-color);\n",
       "    border-color: transparent;\n",
       "    border-bottom-color: var(--fill-color);\n",
       "    animation:\n",
       "      spin 1s steps(1) infinite;\n",
       "  }\n",
       "\n",
       "  @keyframes spin {\n",
       "    0% {\n",
       "      border-color: transparent;\n",
       "      border-bottom-color: var(--fill-color);\n",
       "      border-left-color: var(--fill-color);\n",
       "    }\n",
       "    20% {\n",
       "      border-color: transparent;\n",
       "      border-left-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "    }\n",
       "    30% {\n",
       "      border-color: transparent;\n",
       "      border-left-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "      border-right-color: var(--fill-color);\n",
       "    }\n",
       "    40% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "      border-top-color: var(--fill-color);\n",
       "    }\n",
       "    60% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "    }\n",
       "    80% {\n",
       "      border-color: transparent;\n",
       "      border-right-color: var(--fill-color);\n",
       "      border-bottom-color: var(--fill-color);\n",
       "    }\n",
       "    90% {\n",
       "      border-color: transparent;\n",
       "      border-bottom-color: var(--fill-color);\n",
       "    }\n",
       "  }\n",
       "</style>\n",
       "\n",
       "  <script>\n",
       "    async function quickchart(key) {\n",
       "      const quickchartButtonEl =\n",
       "        document.querySelector('#' + key + ' button');\n",
       "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
       "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
       "      try {\n",
       "        const charts = await google.colab.kernel.invokeFunction(\n",
       "            'suggestCharts', [key], {});\n",
       "      } catch (error) {\n",
       "        console.error('Error during call to suggestCharts:', error);\n",
       "      }\n",
       "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
       "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
       "    }\n",
       "    (() => {\n",
       "      let quickchartButtonEl =\n",
       "        document.querySelector('#df-aa396d9e-3333-4c90-8cd8-a8e6421bd114 button');\n",
       "      quickchartButtonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "    })();\n",
       "  </script>\n",
       "</div>\n",
       "    </div>\n",
       "  </div>\n"
      ],
      "text/plain": [
       "                                             document  \\\n",
       "0   kids in bus accident mocked by kids in passing...   \n",
       "1           these two words are stealing your freedom   \n",
       "2   bush vows to do 'that thing gore just said, on...   \n",
       "3   scotland's parliament backs new independence r...   \n",
       "4        joe biden: being vice president is 'a bitch'   \n",
       "5   u.s. army now just chasing single remaining is...   \n",
       "6                sheryl crow's freshness date expires   \n",
       "7   new ebola quarantine protocol seen as barrier ...   \n",
       "8   the secret to building a successful business t...   \n",
       "9                                    school for crime   \n",
       "10  want to increase trust? increase your say/do r...   \n",
       "11               when autocorrect and sexting collide   \n",
       "12  the house science committee doesn't seem to un...   \n",
       "13  eric clapton wows audience with even slower ve...   \n",
       "14                       rick perry returning to iowa   \n",
       "15         one beer can't do local alcoholic any harm   \n",
       "16  couple at point where they're comfortable usin...   \n",
       "17  watch how mountains of trash spread across the...   \n",
       "18                  lowly mortal opens portal to hell   \n",
       "19  stephen hawking reportedly working on juicy te...   \n",
       "20               offshorers demand: no taxes, no risk   \n",
       "21  troubling study finds majority of americans wh...   \n",
       "22         annoying man more annoying after skydiving   \n",
       "23                              robin hood foundation   \n",
       "24  passenger glued to airplane window like it fuc...   \n",
       "25  amazingly humanlike robot able to commit thous...   \n",
       "26  tourists describe scenes of horror in tunisian...   \n",
       "27           is your christmas present spying on you?   \n",
       "28      area man busts his ass all day, and for what?   \n",
       "29  department of interior employee caught embezzl...   \n",
       "30  new software yellows neglected digital photos ...   \n",
       "31     read live updates on the cnn democratic debate   \n",
       "32  new poultry stripe gum hardly tastes like goos...   \n",
       "33  new film takes an honest look at life with a t...   \n",
       "34  vice president pence pushes expansive nato and...   \n",
       "35  mom tucks handwritten guide on how to use netf...   \n",
       "36  man insists facebook friend actually reads 'wh...   \n",
       "37  internet explorer makes desperate overture to ...   \n",
       "38                    rock song takes pro-rock stance   \n",
       "39  college still looking for absolute saddest pla...   \n",
       "40  alton sterling's family demands action from ba...   \n",
       "41  ronda rousey wants to show you how ripped she ...   \n",
       "42  the workplace revolution: adding company cultu...   \n",
       "43  wolf blitzer walks into middle of olive garden...   \n",
       "44  grandchild, grandfather equally dreading colla...   \n",
       "45  congress reassures nervous zuckerberg they won...   \n",
       "46  senators lured back to emergency session by pr...   \n",
       "47  powerball officials remove plastic balls from ...   \n",
       "48        rude guy unfortunately says something funny   \n",
       "49                           the room i carry with me   \n",
       "\n",
       "                 sentence_embedding_small_bert_L2_128 sentiment  \\\n",
       "0   [-0.7924436926841736, -0.07141707092523575, -0...  negative   \n",
       "1   [-1.028885006904602, -0.7214630246162415, 0.12...  negative   \n",
       "2   [-1.7108917236328125, 0.2942552864551544, -0.3...  negative   \n",
       "3   [0.14012272655963898, 0.7012102603912354, -0.0...  negative   \n",
       "4   [-0.571045458316803, 0.5463784337043762, -0.17...  negative   \n",
       "5   [-0.9116203188896179, -0.3868906497955322, -0....  negative   \n",
       "6   [-1.388686180114746, 0.5200713872909546, -0.43...  negative   \n",
       "7   [-0.6295406222343445, 0.43973761796951294, -0....  negative   \n",
       "8   [-0.1442088484764099, 0.5362765192985535, -0.5...  negative   \n",
       "9   [-1.4345587491989136, 0.35326844453811646, -1....  negative   \n",
       "10  [-1.2950726747512817, 1.153881311416626, -0.36...  negative   \n",
       "11  [-1.1433782577514648, 0.25382623076438904, -0....  negative   \n",
       "12  [-0.24199619889259338, 0.8295924663543701, -0....  negative   \n",
       "13  [-0.12445597350597382, -0.2018168419599533, 0....  negative   \n",
       "14  [-1.3457694053649902, 0.5665305852890015, -0.5...  negative   \n",
       "15  [-1.3927576541900635, 0.6284745335578918, -0.5...  negative   \n",
       "16  [-1.5534732341766357, 0.2146364003419876, -0.6...  negative   \n",
       "17  [-1.8412539958953857, 0.1492537260055542, -0.0...  negative   \n",
       "18  [-0.8720283508300781, -1.011899709701538, -0.3...  negative   \n",
       "19  [-0.7349460124969482, -0.011331072077155113, 0...  negative   \n",
       "20  [-1.0823032855987549, 1.29856276512146, -0.915...  negative   \n",
       "21  [-0.7015470862388611, -0.17110034823417664, -0...  negative   \n",
       "22  [-1.4149224758148193, -1.0473958253860474, 0.1...  negative   \n",
       "23  [-0.057901788502931595, 0.8722413778305054, -0...  negative   \n",
       "24  [-0.33463752269744873, 0.7636221051216125, -0....  negative   \n",
       "25  [-1.2185980081558228, -0.9673603177070618, -0....  negative   \n",
       "26  [-1.1378378868103027, -1.2116812467575073, -0....  negative   \n",
       "27  [-0.8687025308609009, -0.0924399271607399, -0....  negative   \n",
       "28  [-2.376340627670288, -0.3160030245780945, -0.4...  negative   \n",
       "29  [-1.1687604188919067, 0.5776483416557312, -0.6...  negative   \n",
       "30  [-0.773508608341217, 0.5193011164665222, -0.54...  negative   \n",
       "31  [-1.1500324010849, -0.5574671626091003, 0.3618...  negative   \n",
       "32  [-1.2104802131652832, 0.2168104648590088, -0.0...  negative   \n",
       "33  [-0.27279043197631836, -0.44589897990226746, -...  negative   \n",
       "34  [0.06816250830888748, 0.562971830368042, -0.57...  negative   \n",
       "35  [-1.1668932437896729, 0.6492086052894592, -0.3...  negative   \n",
       "36  [-0.41535136103630066, -0.6858690977096558, -0...  negative   \n",
       "37  [-0.058107126504182816, -0.19895373284816742, ...  negative   \n",
       "38  [-0.8466075658798218, -0.350190132856369, 0.33...  negative   \n",
       "39  [-0.8797492384910583, -0.09284910559654236, -0...  negative   \n",
       "40  [-1.123725175857544, 0.27766698598861694, -0.4...  negative   \n",
       "41  [-0.704077959060669, 0.4832143783569336, -0.43...  negative   \n",
       "42  [-0.6472877860069275, 0.819389283657074, -0.50...  negative   \n",
       "43  [-1.089509129524231, -0.010750504210591316, -0...  negative   \n",
       "44  [-0.9178588390350342, -0.05760730057954788, -0...  negative   \n",
       "45  [-0.723938524723053, 0.5092206597328186, -0.02...  negative   \n",
       "46  [-2.088550567626953, 0.19368097186088562, -0.7...  negative   \n",
       "47  [-1.236419916152954, 0.6744992733001709, -0.52...  negative   \n",
       "48  [-0.9946603775024414, -0.6593665480613708, 0.3...  negative   \n",
       "49  [-1.4270148277282715, 0.47338584065437317, -0....  negative   \n",
       "\n",
       "   sentiment_confidence                                               text  \\\n",
       "0                   7.0  kids in bus accident mocked by kids in passing...   \n",
       "1                   1.0          these two words are stealing your freedom   \n",
       "2                   1.0  bush vows to do 'that thing gore just said, on...   \n",
       "3                   5.0  scotland's parliament backs new independence r...   \n",
       "4                   2.0       joe biden: being vice president is 'a bitch'   \n",
       "5                   1.0  u.s. army now just chasing single remaining is...   \n",
       "6                   1.0               sheryl crow's freshness date expires   \n",
       "7                   1.0  new ebola quarantine protocol seen as barrier ...   \n",
       "8                   4.0  the secret to building a successful business t...   \n",
       "9                   1.0                                   school for crime   \n",
       "10                  1.0  want to increase trust? increase your say/do r...   \n",
       "11                  1.0               when autocorrect and sexting collide   \n",
       "12                  7.0  the house science committee doesn't seem to un...   \n",
       "13                  6.0  eric clapton wows audience with even slower ve...   \n",
       "14                  1.0                       rick perry returning to iowa   \n",
       "15                  6.0         one beer can't do local alcoholic any harm   \n",
       "16                  2.0  couple at point where they're comfortable usin...   \n",
       "17                  4.0  watch how mountains of trash spread across the...   \n",
       "18                  6.0                  lowly mortal opens portal to hell   \n",
       "19                  5.0  stephen hawking reportedly working on juicy te...   \n",
       "20                  2.0               offshorers demand: no taxes, no risk   \n",
       "21                  5.0  troubling study finds majority of americans wh...   \n",
       "22                  1.0         annoying man more annoying after skydiving   \n",
       "23                  6.0                              robin hood foundation   \n",
       "24                  1.0  passenger glued to airplane window like it fuc...   \n",
       "25                  3.0  amazingly humanlike robot able to commit thous...   \n",
       "26                  5.0  tourists describe scenes of horror in tunisian...   \n",
       "27                  3.0           is your christmas present spying on you?   \n",
       "28                  5.0      area man busts his ass all day, and for what?   \n",
       "29                  2.0  department of interior employee caught embezzl...   \n",
       "30                  9.0  new software yellows neglected digital photos ...   \n",
       "31                  8.0     read live updates on the cnn democratic debate   \n",
       "32                  1.0  new poultry stripe gum hardly tastes like goos...   \n",
       "33                  4.0  new film takes an honest look at life with a t...   \n",
       "34                  3.0  vice president pence pushes expansive nato and...   \n",
       "35                  2.0  mom tucks handwritten guide on how to use netf...   \n",
       "36                  7.0  man insists facebook friend actually reads 'wh...   \n",
       "37                  2.0  internet explorer makes desperate overture to ...   \n",
       "38                  4.0                    rock song takes pro-rock stance   \n",
       "39                  9.0  college still looking for absolute saddest pla...   \n",
       "40                  3.0  alton sterling's family demands action from ba...   \n",
       "41                  1.0  ronda rousey wants to show you how ripped she ...   \n",
       "42                  2.0  the workplace revolution: adding company cultu...   \n",
       "43                  1.0  wolf blitzer walks into middle of olive garden...   \n",
       "44                  4.0  grandchild, grandfather equally dreading colla...   \n",
       "45                  1.0  congress reassures nervous zuckerberg they won...   \n",
       "46                  3.0  senators lured back to emergency session by pr...   \n",
       "47                  1.0  powerball officials remove plastic balls from ...   \n",
       "48                  6.0        rude guy unfortunately says something funny   \n",
       "49                  4.0                           the room i carry with me   \n",
       "\n",
       "           y  \n",
       "0   positive  \n",
       "1   negative  \n",
       "2   positive  \n",
       "3   negative  \n",
       "4   negative  \n",
       "5   positive  \n",
       "6   positive  \n",
       "7   negative  \n",
       "8   negative  \n",
       "9   negative  \n",
       "10  negative  \n",
       "11  negative  \n",
       "12  negative  \n",
       "13  positive  \n",
       "14  negative  \n",
       "15  positive  \n",
       "16  positive  \n",
       "17  negative  \n",
       "18  positive  \n",
       "19  positive  \n",
       "20  negative  \n",
       "21  positive  \n",
       "22  positive  \n",
       "23  negative  \n",
       "24  positive  \n",
       "25  positive  \n",
       "26  negative  \n",
       "27  negative  \n",
       "28  positive  \n",
       "29  positive  \n",
       "30  positive  \n",
       "31  negative  \n",
       "32  positive  \n",
       "33  negative  \n",
       "34  negative  \n",
       "35  positive  \n",
       "36  positive  \n",
       "37  positive  \n",
       "38  positive  \n",
       "39  positive  \n",
       "40  negative  \n",
       "41  negative  \n",
       "42  negative  \n",
       "43  positive  \n",
       "44  positive  \n",
       "45  positive  \n",
       "46  positive  \n",
       "47  positive  \n",
       "48  positive  \n",
       "49  negative  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Train longer!\n",
    "trainable_pipe = nlp.load('train.sentiment')\n",
    "trainable_pipe['trainable_sentiment_dl'].setMaxEpochs(5)\n",
    "fitted_pipe = trainable_pipe.fit(train_df.iloc[:50])\n",
    "# predict with the trainable pipeline on dataset and get predictions\n",
    "preds = fitted_pipe.predict(train_df.iloc[:50],output_level='document')\n",
    "\n",
    "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
    "preds.dropna(inplace=True)\n",
    "print(classification_report(preds['y'], preds['sentiment']))\n",
    "\n",
    "preds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qFoT-s1MjTSS"
   },
   "source": [
    "# 7. Try training with different Embeddings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "nxWFzQOhjWC8",
    "outputId": "c87f2bce-fbf5-45d5-e6f2-1204f1897958"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For language <am> NLU provides the following Models : \n",
      "nlu.load('am.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_amharic\n",
      "For language <de> NLU provides the following Models : \n",
      "nlu.load('de.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
      "For language <el> NLU provides the following Models : \n",
      "nlu.load('el.embed_sentence.bert.base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
      "For language <en> NLU provides the following Models : \n",
      "nlu.load('en.embed_sentence') returns Spark NLP model_anno_obj tfhub_use\n",
      "nlu.load('en.embed_sentence.albert') returns Spark NLP model_anno_obj albert_base_uncased\n",
      "nlu.load('en.embed_sentence.bert') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
      "nlu.load('en.embed_sentence.bert.base_uncased_legal') returns Spark NLP model_anno_obj sent_bert_base_uncased_legal\n",
      "nlu.load('en.embed_sentence.bert.finetuned') returns Spark NLP model_anno_obj sbert_setfit_finetuned_financial_text_classification\n",
      "nlu.load('en.embed_sentence.bert.pubmed') returns Spark NLP model_anno_obj sent_bert_pubmed\n",
      "nlu.load('en.embed_sentence.bert.pubmed_squad2') returns Spark NLP model_anno_obj sent_bert_pubmed_squad2\n",
      "nlu.load('en.embed_sentence.bert.wiki_books') returns Spark NLP model_anno_obj sent_bert_wiki_books\n",
      "nlu.load('en.embed_sentence.bert.wiki_books_mnli') returns Spark NLP model_anno_obj sent_bert_wiki_books_mnli\n",
      "nlu.load('en.embed_sentence.bert.wiki_books_qnli') returns Spark NLP model_anno_obj sent_bert_wiki_books_qnli\n",
      "nlu.load('en.embed_sentence.bert.wiki_books_qqp') returns Spark NLP model_anno_obj sent_bert_wiki_books_qqp\n",
      "nlu.load('en.embed_sentence.bert.wiki_books_squad2') returns Spark NLP model_anno_obj sent_bert_wiki_books_squad2\n",
      "nlu.load('en.embed_sentence.bert.wiki_books_sst2') returns Spark NLP model_anno_obj sent_bert_wiki_books_sst2\n",
      "nlu.load('en.embed_sentence.bert_base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
      "nlu.load('en.embed_sentence.bert_base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
      "nlu.load('en.embed_sentence.bert_large_cased') returns Spark NLP model_anno_obj sent_bert_large_cased\n",
      "nlu.load('en.embed_sentence.bert_large_uncased') returns Spark NLP model_anno_obj sent_bert_large_uncased\n",
      "nlu.load('en.embed_sentence.bert_use_cmlm_en_base') returns Spark NLP model_anno_obj sent_bert_use_cmlm_en_base\n",
      "nlu.load('en.embed_sentence.bert_use_cmlm_en_large') returns Spark NLP model_anno_obj sent_bert_use_cmlm_en_large\n",
      "nlu.load('en.embed_sentence.biobert.clinical_base_cased') returns Spark NLP model_anno_obj sent_biobert_clinical_base_cased\n",
      "nlu.load('en.embed_sentence.biobert.discharge_base_cased') returns Spark NLP model_anno_obj sent_biobert_discharge_base_cased\n",
      "nlu.load('en.embed_sentence.biobert.pmc_base_cased') returns Spark NLP model_anno_obj sent_biobert_pmc_base_cased\n",
      "nlu.load('en.embed_sentence.biobert.pubmed_base_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_base_cased\n",
      "nlu.load('en.embed_sentence.biobert.pubmed_large_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_large_cased\n",
      "nlu.load('en.embed_sentence.biobert.pubmed_pmc_base_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_pmc_base_cased\n",
      "nlu.load('en.embed_sentence.covidbert.large_uncased') returns Spark NLP model_anno_obj sent_covidbert_large_uncased\n",
      "nlu.load('en.embed_sentence.distil_roberta.distilled_base') returns Spark NLP model_anno_obj sent_distilroberta_base\n",
      "nlu.load('en.embed_sentence.doc2vec') returns Spark NLP model_anno_obj doc2vec_gigaword_300\n",
      "nlu.load('en.embed_sentence.doc2vec.gigaword_300') returns Spark NLP model_anno_obj doc2vec_gigaword_300\n",
      "nlu.load('en.embed_sentence.doc2vec.gigaword_wiki_300') returns Spark NLP model_anno_obj doc2vec_gigaword_wiki_300\n",
      "nlu.load('en.embed_sentence.electra') returns Spark NLP model_anno_obj sent_electra_small_uncased\n",
      "nlu.load('en.embed_sentence.electra_base_uncased') returns Spark NLP model_anno_obj sent_electra_base_uncased\n",
      "nlu.load('en.embed_sentence.electra_large_uncased') returns Spark NLP model_anno_obj sent_electra_large_uncased\n",
      "nlu.load('en.embed_sentence.electra_small_uncased') returns Spark NLP model_anno_obj sent_electra_small_uncased\n",
      "nlu.load('en.embed_sentence.roberta.base') returns Spark NLP model_anno_obj sent_roberta_base\n",
      "nlu.load('en.embed_sentence.roberta.large') returns Spark NLP model_anno_obj sent_roberta_large\n",
      "nlu.load('en.embed_sentence.small_bert_L10_128') returns Spark NLP model_anno_obj sent_small_bert_L10_128\n",
      "nlu.load('en.embed_sentence.small_bert_L10_256') returns Spark NLP model_anno_obj sent_small_bert_L10_256\n",
      "nlu.load('en.embed_sentence.small_bert_L10_512') returns Spark NLP model_anno_obj sent_small_bert_L10_512\n",
      "nlu.load('en.embed_sentence.small_bert_L10_768') returns Spark NLP model_anno_obj sent_small_bert_L10_768\n",
      "nlu.load('en.embed_sentence.small_bert_L12_128') returns Spark NLP model_anno_obj sent_small_bert_L12_128\n",
      "nlu.load('en.embed_sentence.small_bert_L12_256') returns Spark NLP model_anno_obj sent_small_bert_L12_256\n",
      "nlu.load('en.embed_sentence.small_bert_L12_512') returns Spark NLP model_anno_obj sent_small_bert_L12_512\n",
      "nlu.load('en.embed_sentence.small_bert_L12_768') returns Spark NLP model_anno_obj sent_small_bert_L12_768\n",
      "nlu.load('en.embed_sentence.small_bert_L2_128') returns Spark NLP model_anno_obj sent_small_bert_L2_128\n",
      "nlu.load('en.embed_sentence.small_bert_L2_256') returns Spark NLP model_anno_obj sent_small_bert_L2_256\n",
      "nlu.load('en.embed_sentence.small_bert_L2_512') returns Spark NLP model_anno_obj sent_small_bert_L2_512\n",
      "nlu.load('en.embed_sentence.small_bert_L2_768') returns Spark NLP model_anno_obj sent_small_bert_L2_768\n",
      "nlu.load('en.embed_sentence.small_bert_L4_128') returns Spark NLP model_anno_obj sent_small_bert_L4_128\n",
      "nlu.load('en.embed_sentence.small_bert_L4_256') returns Spark NLP model_anno_obj sent_small_bert_L4_256\n",
      "nlu.load('en.embed_sentence.small_bert_L4_512') returns Spark NLP model_anno_obj sent_small_bert_L4_512\n",
      "nlu.load('en.embed_sentence.small_bert_L4_768') returns Spark NLP model_anno_obj sent_small_bert_L4_768\n",
      "nlu.load('en.embed_sentence.small_bert_L6_128') returns Spark NLP model_anno_obj sent_small_bert_L6_128\n",
      "nlu.load('en.embed_sentence.small_bert_L6_256') returns Spark NLP model_anno_obj sent_small_bert_L6_256\n",
      "nlu.load('en.embed_sentence.small_bert_L6_512') returns Spark NLP model_anno_obj sent_small_bert_L6_512\n",
      "nlu.load('en.embed_sentence.small_bert_L6_768') returns Spark NLP model_anno_obj sent_small_bert_L6_768\n",
      "nlu.load('en.embed_sentence.small_bert_L8_128') returns Spark NLP model_anno_obj sent_small_bert_L8_128\n",
      "nlu.load('en.embed_sentence.small_bert_L8_256') returns Spark NLP model_anno_obj sent_small_bert_L8_256\n",
      "nlu.load('en.embed_sentence.small_bert_L8_512') returns Spark NLP model_anno_obj sent_small_bert_L8_512\n",
      "nlu.load('en.embed_sentence.small_bert_L8_768') returns Spark NLP model_anno_obj sent_small_bert_L8_768\n",
      "nlu.load('en.embed_sentence.tfhub_use') returns Spark NLP model_anno_obj tfhub_use\n",
      "nlu.load('en.embed_sentence.tfhub_use.lg') returns Spark NLP model_anno_obj tfhub_use_lg\n",
      "nlu.load('en.embed_sentence.use') returns Spark NLP model_anno_obj tfhub_use\n",
      "nlu.load('en.embed_sentence.use.lg') returns Spark NLP model_anno_obj tfhub_use_lg\n",
      "For language <es> NLU provides the following Models : \n",
      "nlu.load('es.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
      "nlu.load('es.embed_sentence.bert.base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
      "For language <fi> NLU provides the following Models : \n",
      "nlu.load('fi.embed_sentence.bert') returns Spark NLP model_anno_obj bert_base_finnish_uncased\n",
      "nlu.load('fi.embed_sentence.bert.cased') returns Spark NLP model_anno_obj bert_base_finnish_cased\n",
      "nlu.load('fi.embed_sentence.bert.uncased') returns Spark NLP model_anno_obj bert_base_finnish_uncased\n",
      "For language <ha> NLU provides the following Models : \n",
      "nlu.load('ha.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_hausa\n",
      "For language <ig> NLU provides the following Models : \n",
      "nlu.load('ig.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_igbo\n",
      "For language <lg> NLU provides the following Models : \n",
      "nlu.load('lg.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_luganda\n",
      "For language <nl> NLU provides the following Models : \n",
      "nlu.load('nl.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
      "For language <pcm> NLU provides the following Models : \n",
      "nlu.load('pcm.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_naija\n",
      "For language <pt> NLU provides the following Models : \n",
      "nlu.load('pt.embed_sentence.bert.base_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_base_tsdae_sts\n",
      "nlu.load('pt.embed_sentence.bert.cased_large_legal') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.1\n",
      "nlu.load('pt.embed_sentence.bert.large_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_gpl_sts\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.10.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.10\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.2.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.2\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.3.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.3\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.4.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.4\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.5.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.5\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.7.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.7\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.8.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.8\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.9.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.9\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v1.0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v1.0\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_gpl_nli_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_gpl_nli_sts_v0\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_gpl_nli_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_gpl_nli_sts_v1\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_nli_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_nli_sts_v0\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_nli_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_nli_sts_v1\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_sts_v0\n",
      "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_sts_v1\n",
      "nlu.load('pt.embed_sentence.bert.v2_base_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base_ma_v2\n",
      "nlu.load('pt.embed_sentence.bert.v2_large_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts_v2\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.assin.base.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base_ma\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.assin2.base.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_ma.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_ma\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_ma_v3.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_ma_v3\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_sts_v4.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts_v4\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_v4_gpl_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_v4_gpl_sts\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.v2_large_sts_v2.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_v2\n",
      "nlu.load('pt.embed_sentence.bertimbau.legal.v2_large_v2_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_v2_sts\n",
      "For language <rw> NLU provides the following Models : \n",
      "nlu.load('rw.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_kinyarwanda\n",
      "For language <sv> NLU provides the following Models : \n",
      "nlu.load('sv.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
      "For language <sw> NLU provides the following Models : \n",
      "nlu.load('sw.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_swahili\n",
      "For language <wo> NLU provides the following Models : \n",
      "nlu.load('wo.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_wolof\n",
      "For language <xx> NLU provides the following Models : \n",
      "nlu.load('xx.embed_sentence') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
      "nlu.load('xx.embed_sentence.bert') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
      "nlu.load('xx.embed_sentence.bert.cased') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
      "nlu.load('xx.embed_sentence.bert.muril') returns Spark NLP model_anno_obj sent_bert_muril\n",
      "nlu.load('xx.embed_sentence.bert_use_cmlm_multi_base') returns Spark NLP model_anno_obj sent_bert_use_cmlm_multi_base\n",
      "nlu.load('xx.embed_sentence.bert_use_cmlm_multi_base_br') returns Spark NLP model_anno_obj sent_bert_use_cmlm_multi_base_br\n",
      "nlu.load('xx.embed_sentence.labse') returns Spark NLP model_anno_obj labse\n",
      "nlu.load('xx.embed_sentence.xlm_roberta.base') returns Spark NLP model_anno_obj sent_xlm_roberta_base\n",
      "For language <yo> NLU provides the following Models : \n",
      "nlu.load('yo.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_yoruba\n",
      "For language <zh> NLU provides the following Models : \n",
      "nlu.load('zh.embed_sentence.bert') returns Spark NLP model_anno_obj sbert_chinese_qmc_finance_v1\n",
      "nlu.load('zh.embed_sentence.bert.distilled') returns Spark NLP model_anno_obj sbert_chinese_qmc_finance_v1_distill\n"
     ]
    }
   ],
   "source": [
    "# We can use nlu.print_components(action='embed_sentence') to see every possibler sentence embedding we could use. Lets use bert!\n",
    "nlp.nlu.print_components(action='embed_sentence')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "IKK_Ii_gjJfF",
    "outputId": "14ac0c42-1969-435b-a834-d48601c15b2c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning::Spark Session already created, some configs may not take.\n",
      "Warning::Spark Session already created, some configs may not take.\n",
      "sent_small_bert_L12_768 download started this may take some time.\n",
      "Approximate size to download 392.9 MB\n",
      "[OK!]\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "    negative       0.92      0.86      0.89       542\n",
      "     neutral       0.00      0.00      0.00         0\n",
      "    positive       0.89      0.85      0.87       458\n",
      "\n",
      "    accuracy                           0.86      1000\n",
      "   macro avg       0.60      0.57      0.59      1000\n",
      "weighted avg       0.91      0.86      0.88      1000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "trainable_pipe = nlp.load('en.embed_sentence.small_bert_L12_768 train.sentiment')\n",
    "# We need to train longer and user smaller LR for NON-USE based sentence embeddings usually\n",
    "# We could tune the hyperparameters further with hyperparameter tuning methods like gridsearch\n",
    "# Also longer training gives more accuracy\n",
    "trainable_pipe['trainable_sentiment_dl'].setMaxEpochs(120)\n",
    "trainable_pipe['trainable_sentiment_dl'].setLr(0.0005)\n",
    "fitted_pipe = trainable_pipe.fit(train_df[:1000])\n",
    "# predict with the trainable pipeline on dataset and get predictions\n",
    "preds = fitted_pipe.predict(train_df[:1000],output_level='document')\n",
    "\n",
    "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
    "preds.dropna(inplace=True)\n",
    "print(classification_report(preds['y'], preds['sentiment']))\n",
    "\n",
    "#preds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "_1jxw3GnVGlI"
   },
   "source": [
    "# 7.1 evaluate on Test Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "Fxx4yNkNVGFl",
    "outputId": "542c6589-d1f1-4310-c0b3-0717bdd4111e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "    negative       0.76      0.79      0.78        53\n",
      "     neutral       0.00      0.00      0.00         0\n",
      "    positive       0.82      0.60      0.69        47\n",
      "\n",
      "    accuracy                           0.70       100\n",
      "   macro avg       0.53      0.46      0.49       100\n",
      "weighted avg       0.79      0.70      0.74       100\n",
      "\n"
     ]
    }
   ],
   "source": [
    "preds = fitted_pipe.predict(test_df[:100],output_level='document')\n",
    "\n",
    "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
    "preds.dropna(inplace=True)\n",
    "print(classification_report(preds['y'], preds['sentiment']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "2BB-NwZUoHSe"
   },
   "source": [
    "# 8. Lets save the model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "eLex095goHwm"
   },
   "outputs": [],
   "source": [
    "stored_model_path = './models/classifier_dl_trained'\n",
    "fitted_pipe.save(stored_model_path)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "e_b2DPd4rCiU"
   },
   "source": [
    "# 9. Lets load the model from HDD.\n",
    "This makes Offlien NLU usage possible!   \n",
    "You need to call nlu.load(path=path_to_the_pipe) to load a model/pipeline from disk."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 133
    },
    "id": "SO4uz45MoRgp",
    "outputId": "a37045b7-f9d1-4fbc-fbd2-8ab0731d2614"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning::Spark Session already created, some configs may not take.\n",
      "Warning::Spark Session already created, some configs may not take.\n",
      "Warning::Spark Session already created, some configs may not take.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"df-349d6e08-4ee6-483b-9d3a-45cc7e111b11\" class=\"colab-df-container\">\n",
       "    <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>document</th>\n",
       "      <th>sentence_embedding_from_disk</th>\n",
       "      <th>sentiment</th>\n",
       "      <th>sentiment_confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Aliens are immortal!</td>\n",
       "      <td>[0.3093056380748749, 0.1294729858636856, 0.065...</td>\n",
       "      <td>negative</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "    <div class=\"colab-df-buttons\">\n",
       "\n",
       "  <div class=\"colab-df-container\">\n",
       "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-349d6e08-4ee6-483b-9d3a-45cc7e111b11')\"\n",
       "            title=\"Convert this dataframe to an interactive table.\"\n",
       "            style=\"display:none;\">\n",
       "\n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
       "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
       "  </svg>\n",
       "    </button>\n",
       "\n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    .colab-df-buttons div {\n",
       "      margin-bottom: 4px;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "    <script>\n",
       "      const buttonEl =\n",
       "        document.querySelector('#df-349d6e08-4ee6-483b-9d3a-45cc7e111b11 button.colab-df-convert');\n",
       "      buttonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "      async function convertToInteractive(key) {\n",
       "        const element = document.querySelector('#df-349d6e08-4ee6-483b-9d3a-45cc7e111b11');\n",
       "        const dataTable =\n",
       "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                    [key], {});\n",
       "        if (!dataTable) return;\n",
       "\n",
       "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "          + ' to learn more about interactive tables.';\n",
       "        element.innerHTML = '';\n",
       "        dataTable['output_type'] = 'display_data';\n",
       "        await google.colab.output.renderOutput(dataTable, element);\n",
       "        const docLink = document.createElement('div');\n",
       "        docLink.innerHTML = docLinkHtml;\n",
       "        element.appendChild(docLink);\n",
       "      }\n",
       "    </script>\n",
       "  </div>\n",
       "\n",
       "    </div>\n",
       "  </div>\n"
      ],
      "text/plain": [
       "               document                       sentence_embedding_from_disk  \\\n",
       "0  Aliens are immortal!  [0.3093056380748749, 0.1294729858636856, 0.065...   \n",
       "\n",
       "  sentiment sentiment_confidence  \n",
       "0  negative                  0.0  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hdd_pipe = nlp.load(path=stored_model_path)\n",
    "\n",
    "preds = hdd_pipe.predict('Aliens are immortal!')\n",
    "\n",
    "preds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "e0CVlkk9v6Qi",
    "outputId": "4edc51a7-f104-4c0e-a480-58f5a2f62d6e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The following parameters are configurable for this NLU pipeline (You can copy paste the examples) :\n",
      ">>> component_list['document_assembler'] has settable params:\n",
      "component_list['document_assembler'].setCleanupMode('shrink')                                    | Info: possible values: disabled, inplace, inplace_full, shrink, shrink_full, each, each_full, delete_full | Currently set to : shrink\n",
      ">>> component_list['bert_sentence_embeddings@sent_small_bert_L12_768'] has settable params:\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setBatchSize(8)               | Info: Size of every batch | Currently set to : 8\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setCaseSensitive(False)       | Info: whether to ignore case in tokens for embeddings matching | Currently set to : False\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setDimension(768)             | Info: Number of embedding dimensions | Currently set to : 768\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setMaxSentenceLength(128)     | Info: Max sentence length to process | Currently set to : 128\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setEngine('tensorflow')       | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setIsLong(False)              | Info: Use Long type instead of Int type for inputs buffer - Some Bert models require Long instead of Int. | Currently set to : False\n",
      "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setStorageRef('sent_small_bert_L12_768')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L12_768\n",
      ">>> component_list['sentiment_dl@sent_small_bert_L12_768'] has settable params:\n",
      "component_list['sentiment_dl@sent_small_bert_L12_768'].setThreshold(0.6)                         | Info: The minimum threshold for the final result otheriwse it will be neutral | Currently set to : 0.6\n",
      "component_list['sentiment_dl@sent_small_bert_L12_768'].setThresholdLabel('neutral')              | Info: In case the score is less than threshold, what should be the label. Default is neutral. | Currently set to : neutral\n",
      "component_list['sentiment_dl@sent_small_bert_L12_768'].setEngine('tensorflow')                   | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
      "component_list['sentiment_dl@sent_small_bert_L12_768'].setClasses(['positive', 'negative'])      | Info: get the tags used to trained this SentimentDLModel | Currently set to : ['positive', 'negative']\n",
      "component_list['sentiment_dl@sent_small_bert_L12_768'].setStorageRef('sent_small_bert_L12_768')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L12_768\n"
     ]
    }
   ],
   "source": [
    "hdd_pipe.print_info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "aq3RCRU4wHsv"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [
    "zkufh760uvF3"
   ],
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
